﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace dbPoll_Application.Models
{
    public class Poll
    {
        public virtual int pollID { get; set; }
        public virtual String name { get; set; }
        public virtual int receiverChannel { get; set; }
        public virtual Boolean genericUsers { get; set; }
        public virtual Boolean anonymous { get; set; }
        public virtual DateTime? pollStart { get; set; }
        public virtual DateTime pollClose { get; set; }
        public virtual double latitude { get; set; }
        public virtual double longitude { get; set; }
        public virtual CountdownTimer defaultCountdownTimer { get; set; }
        public virtual ResponseCounter defaultResponseCounter { get; set; }
        public virtual CorrectAnswerIndicator defaultCorrectAnswerIndicator { get; set; }
        public virtual ResponseGrid defaultResponseGrid { get; set; }
        public virtual String defaultFontType { get; set; }
        public virtual String defaultFontColour { get; set; }
        public virtual int defaultFontSize { get; set; }
        public virtual QuestionChart defaultResultsChart { get; set; }
        public virtual Boolean hasParticipantList { get; set; }
        public virtual IList<User> pollMasters { get; set; }
        public virtual IList<ParticipantField> participantFields { get; set; }
        public virtual IList<Entity> entities { get; set; }
        public virtual IList<Question> questions { get; set; }
        public virtual IList<Participant> participants { get; set; }
        public virtual IList<Message> messages { get; set; }
        public virtual PageInstruction instruction { get; set; }
        public virtual IList<Keypad> gridResponses { get; set; }
        public virtual IList<ParticipantGroup> groups { get; set; }
        public virtual Poll linkedPoll { get; set; }
        public virtual Boolean isTestPoll { get; set; }
        public virtual Boolean hasFinished { get; set; }
        public virtual Boolean isGroup { get; set; }

        public Poll()
        {
            this.pollID = -1;
            this.name = String.Empty;
            this.receiverChannel = 41;
            this.genericUsers = false;
            this.pollStart = null;
            this.pollClose = DateTime.MaxValue;
            this.latitude = 0;
            this.longitude = 0;
            this.defaultCountdownTimer = null;
            this.defaultResponseCounter = null;
            this.defaultCorrectAnswerIndicator = null;
            this.defaultResponseGrid = null;
            this.defaultFontType = String.Empty;
            this.defaultFontColour = String.Empty;
            this.defaultFontSize = 11;
            this.defaultResultsChart = null;
            this.hasParticipantList = false;
            this.anonymous = false;
            this.pollMasters = null;
            this.participantFields = null;
            this.entities = null;
            this.questions = null;
            this.participants = null;
            this.messages = null;
            this.instruction = null;
            this.gridResponses = null;
            this.groups = null;
            this.linkedPoll = null;
            this.isTestPoll = false;
            this.hasFinished = false;
            this.isGroup = false;
        }

        public Poll(double latitude, double longitude)
        {
            this.pollID = -1;
            this.name = String.Empty;
            this.receiverChannel = 41;
            this.genericUsers = false;
            this.pollStart = null;
            this.pollClose = DateTime.MaxValue;
            this.latitude = latitude;
            this.longitude = longitude;
            this.defaultCountdownTimer = new CountdownTimer(false,30);
            this.defaultResponseCounter = new ResponseCounter(false);
            this.defaultCorrectAnswerIndicator = new CorrectAnswerIndicator(false);
            this.defaultResponseGrid = new ResponseGrid(false, "Name");
            this.defaultFontType = "Helvetica";
            this.defaultFontColour = "#000000";
            this.defaultFontSize = 30;
            this.defaultResultsChart = new QuestionChart("Vertical Bar", "Count", "green, orange, yellow, red");
            this.hasParticipantList = false;
            this.anonymous = false;
            this.pollMasters = new List<User>();
            this.participantFields = new List<ParticipantField>();
            this.entities = new List<Entity>();
            this.questions = new List<Question>();
            this.participants = new List<Participant>();
            this.messages = new List<Message>();
            this.instruction = new PageInstruction(String.Empty, String.Empty);
            this.gridResponses = new List<Keypad>();
            this.groups = new List<ParticipantGroup>();
            this.linkedPoll = new Poll(latitude, longitude, this);
            this.isTestPoll = false;
            this.hasFinished = false;
            this.isGroup = false;
        }

        public Poll(double latitude, double longitude, Poll linkedPoll)
        {
            this.pollID = -1;
            this.name = String.Empty;
            this.receiverChannel = 41;
            this.genericUsers = false;
            this.pollStart = null;
            this.pollClose = DateTime.MaxValue;
            this.latitude = latitude;
            this.longitude = longitude;
            this.defaultCountdownTimer = new CountdownTimer(false, 30);
            this.defaultResponseCounter = new ResponseCounter(false);
            this.defaultCorrectAnswerIndicator = new CorrectAnswerIndicator(false);
            this.defaultResponseGrid = new ResponseGrid(false, "Name");
            this.defaultFontType = "Helvetica";
            this.defaultFontColour = "#000000";
            this.defaultFontSize = 30;
            this.defaultResultsChart = new QuestionChart("Vertical Bar", "Count", "green, orange, yellow, red");
            this.hasParticipantList = false;
            this.anonymous = false;
            this.pollMasters = new List<User>();
            this.participantFields = new List<ParticipantField>();
            this.questions = new List<Question>();
            this.participants = new List<Participant>();
            this.messages = new List<Message>();
            this.instruction = new PageInstruction(String.Empty, String.Empty);
            this.gridResponses = new List<Keypad>();
            this.groups = new List<ParticipantGroup>();
            this.linkedPoll = linkedPoll;
            this.isTestPoll = true;
            this.hasFinished = false;
            this.isGroup = false;
        }

        public Poll(String name, int receiverChannel, Boolean genericUsers, Boolean anonymous, DateTime pollStart, DateTime pollClose, double latitude, double longitude)
        {
            this.pollID = -1;
            this.name = name;
            this.receiverChannel = receiverChannel;
            this.genericUsers = genericUsers;
            this.pollStart = pollStart;
            this.pollClose = pollClose;
            this.latitude = latitude;
            this.longitude = longitude;
            this.defaultCountdownTimer = null;
            this.defaultResponseCounter = null;
            this.defaultCorrectAnswerIndicator = null;
            this.defaultResponseGrid = null;
            this.defaultFontType = String.Empty;
            this.defaultFontColour = String.Empty;
            this.defaultFontSize = 30;
            this.defaultResultsChart = null;
            this.hasParticipantList = false;
            this.anonymous = anonymous;
            this.pollMasters = new List<User>();
            this.participantFields = new List<ParticipantField>();
            this.entities = new List<Entity>();
            this.questions = new List<Question>();
            this.participants = new List<Participant>();
            this.messages = new List<Message>();
            this.instruction = new PageInstruction(String.Empty, String.Empty);
            this.gridResponses = new List<Keypad>();
            this.groups = new List<ParticipantGroup>();
            this.linkedPoll = null;
            this.isTestPoll = false;
            this.hasFinished = false;
            this.isGroup = false;
        }

        public Poll(int pollID, String name, int receiverChannel, Boolean genericUsers, Boolean anonymous, DateTime pollStart, DateTime pollClose, double latitude, double longitude, IList<User> pollMasters, IList<ParticipantField> participantFields, IList<Question> questions, IList<Participant> participants, IList<Message> messages)
        {
            this.pollID = pollID;
            this.name = name;
            this.receiverChannel = receiverChannel;
            this.genericUsers = genericUsers;
            this.pollStart = pollStart;
            this.pollClose = pollClose;
            this.latitude = latitude;
            this.longitude = longitude;
            this.defaultCountdownTimer = null;
            this.defaultResponseCounter = null;
            this.defaultCorrectAnswerIndicator = null;
            this.defaultResponseGrid = null;
            this.defaultFontType = String.Empty;
            this.defaultFontColour = String.Empty;
            this.defaultFontSize = 30;
            this.defaultResultsChart = null;
            this.hasParticipantList = false;
            this.anonymous = anonymous;
            this.pollMasters = pollMasters;
            this.participantFields = participantFields;
            this.entities = new List<Entity>();
            this.questions = questions;
            this.participants = participants;
            this.messages = messages;
            this.instruction = new PageInstruction(String.Empty, String.Empty);
            this.gridResponses = new List<Keypad>();
            this.groups = new List<ParticipantGroup>();
            this.linkedPoll = null;
            this.isTestPoll = false;
            this.hasFinished = false;
            this.isGroup = false;
        }

        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }
            var poll = obj as Poll;
            if ((System.Object)poll == null)
            {
                return false;
            }
            return this.pollID == poll.pollID;
        }

        public override int GetHashCode()
        {
            return this.pollID;
        }
    }
}